/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.fiu.accesslog.statistics;

import java.util.Comparator;


/**
 *
 * @author Hasan Mahmud
 * @date Jun 10, 2012
 */
public class InfoComparatorKeyToDouble implements Comparator<Info>
{
      private boolean isAscending = false;
      public InfoComparatorKeyToDouble(boolean isAscending)
      {
            this.isAscending = isAscending;
      }
     @Override
      public int compare(Info o1, Info o2)
      {
            int result = 0;
            try
            {
                    double num1 = Double.parseDouble(o1.keyName);
                    double num2 = Double.parseDouble(o2.keyName);
                if(num1 >num2  )
                {
                        result = -1;
                }
                else if (num1 < num2  )
                {
                        result = 1;
                }
                    
            }
            catch(Exception e)
            {
                    
            }
            
            
            

            
            if(isAscending)
            {
                  result *= -1;
            }
           return result;
      }

}
